<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>__proto__属性</title>
</head>
<body>
    <h1>__proto__属性、Object.setPrototypeOf()、Object.getPrototypeOf()</h1>

    <script>
        // __proto__属性
        const obj = {
            method: function() {}
        };
        const proto = {
            foo: 'bar'
        };

        obj.__proto__ = proto;
        console.log(obj.foo); // "bar"

        // Object.setPrototypeOf()
        const obj2 = {};
        Object.setPrototypeOf(obj2, proto);
        console.log(obj2.foo); // "bar"

        // Object.getPrototypeOf()
        console.log(Object.getPrototypeOf(obj2) === proto); // true
    </script>
</body>
</html> 